<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>键盘事件</title>
  </head>
  <body>
    <p><input id="input" /></p>
    <p><textarea id="textarea" cols="80" rows="20"> </textarea></p>
    <script>
      const input = document.getElementById("input");
      const textarea = document.getElementById("textarea");
      input.onkeydown =
        input.onkeyup =
        input.onkeypress =
          (event) => {
            textarea.value += `type: ${event.type}, key: ${event.key}, code: ${event.code}\n`;
          };
    </script>
  </body>
</html>
